home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / b_fuser.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-01  |  7.9 KB  |  172 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                 This module was written by Bob Hartman                   */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                 BinkleyTerm Fidolist processing module                   */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  27. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  28. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  29. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  30. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /*    The Authors can be reached at the following addresses:                */
  34. /*                                                                          */
  35. /*    Robert C. Hartman                      Vincent E. Perriello           */
  36. /*    Spark Software                         VEP Software                   */
  37. /*    427-3 Amherst Street                   111 Carroll Street             */
  38. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  39. /*    Nashua, NH 03061                                                      */
  40. /*                                                                          */
  41. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  42. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  43. /*                                                                          */
  44. /*    Please feel free to contact us at any time to share your comments     */
  45. /*    about our software and/or licensing policies.                         */
  46. /*                                                                          */
  47. /*--------------------------------------------------------------------------*/
  48.  
  49. #include <stdio.h>
  50. #include <sys\types.h>
  51. #include <sys\stat.h>
  52. #include <fcntl.h>
  53. #include <string.h>
  54. #include <io.h>
  55.  
  56. #include "com.h"
  57. #include "xfer.h"
  58. #include "zmodem.h"
  59. #include "keybd.h"
  60. #include "sbuf.h"
  61. #include "sched.h"
  62. #include "externs.h"
  63. #include "prototyp.h"
  64.  
  65. static int reclength = -1;
  66. static int nrecs = -1;
  67.  
  68. void fidouser (name, zone, net, node, point)
  69. char *name;
  70. int *zone;
  71. int *net;
  72. int *node;
  73. int *point;
  74. {
  75.    int low, high, mid, f, cond, namelen;
  76.    char midname[80];
  77.    char last_name_first[80];
  78.    char *c, *p, *m;
  79.    struct stat buffer;
  80.  
  81.    *zone = *net = *node = *point = -1;
  82.  
  83.    c = midname;                                  /* Start of temp name buff   */
  84.    p = name;                                     /* Point to start of name    */
  85.    m = NULL;                                     /* Init pointer to space     */
  86.  
  87.    while (*c = *p++)                             /* Go entire length of name  */
  88.       {
  89.       if (*c == ' ')                             /* Look for space            */
  90.          m = c;                                  /* Save location             */
  91.       c++;
  92.       }
  93.  
  94.    if (m != NULL)                                /* If we have a pointer,     */
  95.       {
  96.       *m++ = '\0';                               /* Terminate the first half  */
  97.       strcpy (last_name_first, m);               /* Now copy the last name    */
  98.       strcat (last_name_first, ", ");            /* Insert a comma and space  */
  99.       strcat (last_name_first, midname);         /* Finally copy first half   */
  100.       }
  101.    else strcpy (last_name_first, midname);       /* Use whole name otherwise  */
  102.  
  103.    fancy_str (last_name_first);                  /* Get caps in where needed  */
  104.    namelen = strlen (last_name_first);           /* Calc length now           */
  105.  
  106.    midname[0] = '\0';                            /* "null-terminated string"  */
  107.    strcpy (midname, net_info);                   /* take nodelist path        */
  108.    strcat (midname, "FIDOUSER.LST");             /* add in the file name      */
  109.    if ((f = open (midname, O_RDONLY | O_BINARY)) == -1)
  110.       {
  111.       reclength = -1;                            /* Reset all on open failure */
  112.       return;
  113.       }
  114.  
  115.    /* Find out if we have done this before */
  116.    if (reclength == -1)
  117.       {
  118.       /* If not, then determine file size and record length */
  119.  
  120.       fstat (f, &buffer);                        /* Get file stats in buffer  */
  121.       read (f, midname, 80);                     /* Read 1 record             */
  122.       reclength = ((int) strchr (midname, '\n') - (int) midname) + 1;   /* FindEnd */
  123.       nrecs = (int) (buffer.st_size / reclength);/* Now get num of records */
  124.       }
  125.  
  126.    /* Binary search algorithm */
  127.    low = 0;
  128.    high = nrecs - 1;
  129.    while (low <= high)
  130.       {
  131.       mid = low + (high - low) / 2;
  132.       lseek (f, (long) ((long) mid * (long) reclength), SEEK_SET);
  133.       read (f, midname, reclength);
  134.       if ((cond = strnicmp (last_name_first, midname, namelen)) < 0)
  135.          high = mid - 1;
  136.       else
  137.          {
  138.          if (cond > 0)
  139.             low = mid + 1;
  140.          else
  141.             {
  142.             /* Return the address information */
  143.             close (f);
  144.             /* The offset of 40 is just a number that should work properly */
  145.             if (sscanf (&midname[40], "%d:%d/%d.%d", zone, net, node, point) != 4)
  146.                {
  147.                *zone = *net = *node = -1;
  148.                *point = 0;
  149.                if (sscanf (&midname[40], "%d:%d/%d", zone, net, node) != 3)
  150.                   {
  151.                   *net = *node = *point = -1;
  152.                   *zone = alias[0].Zone;
  153.                   if (sscanf (&midname[40], "%d/%d.%d", net, node, point) != 3)
  154.                      {
  155.                      *net = *node = -1;
  156.                      *zone = alias[0].Zone;
  157.                      *point = 0;
  158.                      if (sscanf (&midname[40], "%d/%d", net, node) != 2)
  159.                         {
  160.                         *zone = *net = *node = *point = -1;
  161.                         }
  162.                      }
  163.                   }
  164.                }
  165.             return;
  166.             }
  167.          }
  168.       }
  169.    *zone = *net = *node = *point = -1;
  170.    close (f);
  171. }
  172.